package app.frequentpatterns.fpgrowth;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import app.frequentpatterns.fpgrowth.Database;
import app.frequentpatterns.fpgrowth.Itemsets;

/**
 * Class to test the FPGROWTH algorithm
 * 
 * @author Philippe Fournier-Viger (Copyright 2008)
 */
public class MainTestFPGrowth {

	/**
	 * @param arg
	 */
	public static void main(String[] arg) {
		// Loading the binary context
		Database context = new Database();
		//context.createRandomWeightRange(0.6,0.9);
		context.printAble = true;
		try {
			context.loadFile("D:\\My Books\\My Document\\Test Data\\aaaa");
		    context.loadWeightFile("D:\\My Books\\My Document\\Test Data\\bbbb");
			//context.loadFile("D:\\My Books\\My Document\\Dropbox\\IoitUse\\FIMI_DATA\\T10I4D100K.dat");
			//context.loadWeightFile1("D:\\My Books\\My Document\\Test Data\\weightForT10I4D100K");
			//context.loadFile("E:\\Dropbox\\Dropbox\\IoitUse\\FIMI_DATA\\T10I4D100K.dat");
		   // context.createRandomWeightRange(0.05,0.17);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (context.printAble == true)
			context.printContext();
		// Applying the FPGROWTH algorithmMainTestFPGrowth.java
		//AlgoFPGrowth algo = new AlgoFPGrowth();
		
		//algo.setRandomMin(0.2);
		AlgoCofiTree algo = new AlgoCofiTree();
	    //algo.setRandomMax(0.8);
		//Run algorithm with min sup = [0..1]
		Itemsets patterns = algo.runAlgorithm(context,0.4, 0.7);
		//Itemsets patterns = algo.runAlgorithm(context,0.5, 0.7);
		
		algo.printStats();
		//algo.printStats();
		if (context.printAble == true)
		patterns.printItemsets(context.size());
	}

	public static String fileToPath(String filename)
			throws UnsupportedEncodingException {
		URL url = MainTestFPGrowth.class.getResource(filename);
		return java.net.URLDecoder.decode(url.getPath(), "UTF-8");
	}
}
